package com.blb.zycommunity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blb.zycommunity.entity.ResponseResult;
import com.blb.zycommunity.entity.SysUser;
import com.blb.zycommunity.entity.ZyOwner;
import com.blb.zycommunity.entity.ZyVisitor;
import com.blb.zycommunity.service.IZyVisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>
 * 访客邀请  前端控制器
 * </p>
 *
 * @author chenheng
 * @since 2023-11-20
 */
@RestController
public class ZyVisitorController {

    @Autowired
    private IZyVisitorService zyVisitorService;

    @GetMapping("/visitor-pages")
    public ResponseResult<IPage<ZyVisitor>> findVisitorPage(@RequestParam(required = false,defaultValue = "1") Long current,
                                                          @RequestParam(required = false,defaultValue = "5") Long size,
                                                          @RequestParam(required = false) String communityId,
                                                          @RequestParam(required = false) String visitorName,
                                                          @RequestParam(required = false) String visitorPhoneNumber,
                                                          @RequestParam(required = false)  @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate visitorDate){
        IPage<ZyVisitor> visitorPage = zyVisitorService.findVisitorPage(current, size,communityId, visitorName, visitorPhoneNumber, visitorDate);
        return ResponseResult.ok(visitorPage);
    }

    @PostMapping("/visitor")
    public ResponseResult addUser(@RequestBody ZyVisitor zyVisitor){
//        zyVisitor.setVisitorId();
        zyVisitor.setCreateTime(LocalDateTime.now());
        zyVisitor.setCommunityId("1338423709557272577");
        return ResponseResult.ok(zyVisitorService.save(zyVisitor));
    }

    @GetMapping("/visitors")
    public ResponseResult<IPage<ZyVisitor>> findVisitors(@RequestParam(required = false) String communityId,
                                                          @RequestParam(required = false) String createById){
        List<ZyVisitor> visitors = zyVisitorService.findVisitors(communityId, createById);
        return ResponseResult.ok(visitors);
    }
}
